package com.eibus.applicationconnector.dotnet;

import junit.framework.TestCase;
import com.eibus.connector.nom.Connector;
import com.eibus.exception.TimeoutException;
import com.eibus.xml.nom.Find;
import com.eibus.xml.nom.Node;
import com.eibus.xml.xpath.XPath;

//@Author	: Lejil
//@Class	: TigerRuntimeTest

/**
 *	This class Invokes the methods
 *		TigerRuntime Methods through .NETCall Connector
 *				For all the dataTypes
 */


 /*
 *
 * Java Classes are written with different types of methods.
 *
 *		Employees //Generated over Northwind Method Sets
 *		Manager
 *		ComplexTypes
 *
 *
 *
 *
 * TIGER - c# wrapper classes are generated and build to TigerJunit.dll
 *
 *       * Registered the Assembly in Gac // gacutil -i TigerJunit.dll

 *		 * Exposed methods grouping for differnet catogories
 *
 *
 * .NET Connector -
 *
 *		  Using the metaData Explorer of the .NET Call Connector, web methods
 *			are generated.
 *		  Invoke this methods through .NET Call Connecotr.
 *
 *
 * TIGER COM
 *		.NET Callable wrappers are generated for TIGERCOM, with strong naming
 *
 *		 tlbimp /out:COMJAVALib.dll /keyfile:tiger.snk  TigerCom.dll
 *
 *		Register the Assembly in GAC
 *
 *		gacutil -i COMJAVALib.dll
 *
 *
 */

public class TigerRuntimeTestCase extends TestCase
{

	Connector  connector;

	protected void setUp()
	{
		try
		{
			connector = Connector.getInstance("DotNET Client");
			if (!connector.isOpen())
				connector.open();
		}
		catch(Exception exception)
		{
			fail("Could not get instance of Connector. "+exception.getMessage());
		}
	}


	protected void tearDown()
	{

	}


	public TigerRuntimeTestCase(String name)
	{
		super(name);
	}



	public static void main(String[] args)
	{
		junit.textui.TestRunner.run(TigerRuntimeTestCase.class);
	}
	


	public void  sendRequest(String methodName,String mtdParam)
	{
		try
		{
				int method = connector.createSOAPMethod("http://schemas.cordys.com/1.0/dotnet/TigerRuntime",methodName);
				Node.setDataElement(method,"methodName",mtdParam);
				int response = connector.sendAndWait(Node.getParent(method));
				
				checkforSoapFault(response);
				compareResult(response,methodName);
				Util.delete(Node.getRoot(response));
				Util.delete(Node.getRoot(method));
		}
		catch(TimeoutException tex)
		{
			fail("Tiger Runtime Methods failed for the Method  :- " + methodName +" Exception :-" +tex.toString());
			tex.printStackTrace();
		}
		catch(Exception ex)
		{
			fail("Tiger Runtime Methods failed for the Method  :- " + methodName +" Exception :-" +ex.toString());
		}

	}



	public void  sendRequest(String methodName)
	{
		try
		{
				int method = connector.createSOAPMethod("http://schemas.cordys.com/1.0/dotnet/TigerRuntime",methodName);
				int response = connector.sendAndWait(Node.getParent(method));
				checkforSoapFault(response);
				compareResult(response,methodName);
				Util.delete(Node.getRoot(response));
				Util.delete(Node.getRoot(method));
		}
		catch(TimeoutException tex)
		{
			fail("Tiger Runtime Methods failed for the Method  :- " + methodName);
			tex.printStackTrace();
		}
		catch(Exception ex)
		{
			fail("Tiger Runtime Methods failed for the Method  :- " + methodName);
		}

	}


	public  boolean checkforSoapFault(int response) throws Exception
	{
		try
		{
			int  faultNode = XPathUtil.getSOAPFault(response);

			if ( faultNode != 0)
			{
				fail("Tiger Runtime Methods failed with SOAP Fault :-"+Node.writeToString(faultNode,true));
			}
		}
		catch(Exception ex)
		{
			throw ex;
		}
		return true;
	}



	public void compareResult(int response,String methodName) throws Exception
	{

			String  searchCriteria = "?<"+methodName+"><"+methodName+">";
            //String  searchCriteria = ".//"+methodName+"/"+methodName;
			try
			{
				int resultNode = Find.firstMatch(response,searchCriteria);
                //int resultNode = new XPath(searchCriteria).firstMatch(response, null);
				String result  = Node.getDataWithDefault(resultNode,"false").toLowerCase();

				if (! result.equals("true"))
				{
					fail("Tiger Runtime failed for the  following method :-"+ methodName);
				}
			}
			catch(Exception ex)
			{
				throw ex;
			}

	}


	public void testConnctorGetLDAPObject()
	{
		try
		{
			sendRequest("testConnctorGetLDAPObject");
		}
		catch(Exception ex)
		{
			fail("Tiger Runtime failed for the  following method  testConnectorGetLDAPObject");
		}
	}


	public void testInstanceMethodsWithObjects()
		{
			try
			{
				sendRequest("instanceMethodsWithObjects");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method : instanceMethodsWithObjects");
			}

	}





	public void testStaticMethodsWithObjects()
	{
			try
			{
				sendRequest("staticMethodsWithObjects");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method : staticMethodsWithObjects");
			}

	}



	public void testMixedTypes()
		{
			try
			{
				sendRequest("testMixedTypes");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testMixedTypes");
			}

	}


	public void testParameterConstWithIntArgs ()
	{
			try
			{
				sendRequest("testParameterConstWithIntArgs");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testParameterConstWithIntArgs");
			}
	}


	public void testParameterConstWithStringArgs()
	{
			try
			{
				sendRequest("testParameterConstWithStringArgs");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testParameterConstWithStringArgs");
			}

	}

	public void testParameterConstructors()
	{
			try
			{
				sendRequest("testParameterConstructors");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testParameterConstructors");
			}

	}


	public void testPassingAndReturningArrays()
	{
			try
			{
				sendRequest("testPassingAndReturningArrays");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPassingAndReturningArrays");
			}

	}





	public void testPrimitiveArgsReturnArraysInstance()
	{
			try
			{
				sendRequest("testPrimitiveArgsReturnArraysInstance");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveArgsReturnArraysInstance");
			}
	}



	public void testPrimitiveArgsReturnArraysStatic()
	{
			try
			{
				sendRequest("testPrimitiveArgsReturnArraysStatic");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveArgsReturnArraysStatic");
			}

	}

	///		 INSTACE METHODS  METHODS
	//	TAKES AND RETURN ARRAYS OF DIFFERENT TYPES
	//

	public void testReturnIntegerArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","intMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}

  	//LONG Arrays is Changed to UINT
   /*
	public void testReturnLongArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","longMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}*/

	public void testReturnByteArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","byteMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}
	public void testReturnCharArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","charMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}
	public void testReturnDoubleArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","doubleMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}
	public void testReturnBooleanArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","booleanMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}
	public void testReturnFloatArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","floatMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}
	public void testReturnStringArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","stringMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}

	public void testReturnShortArraysWithInstance()
	{
			try
			{
				sendRequest("testReturnArraysWithInstance","shortMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithInstance");
			}
	}



	///		 STATIC  METHODS   WHICH
	//	TAKES AND RETURN ARRAYS OF DIFFERENT TYPES


	public void testReturnIntegerArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","intMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}
	public void testReturnShortArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","shortMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}

	///LONG Arrays is Changed to UINT

	/*public void testReturnLongArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","longMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}*/

	public void testReturnCharArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","charMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}
	public void testReturnDoubleArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","doubleMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}
	public void testReturnByteArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","byteMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}
	public void testReturnFloatArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","floatMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}
	public void testReturnStringArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","stringMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}
	public void testReturnBooleanArraysWithStatic()
	{
			try
			{
				sendRequest("testReturnArraysWithStatic","booleanMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testReturnArraysWithStatic");
			}
	}

	//--------------------------------------------

	public void testDifferentTypeMethods()
	{

			try
			{
				sendRequest("testDifferentMethods");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testDifferentMethods");
			}
	}





///***************************************************************

//	PRIMITIVE INSTANCE	METHODS
//


	public void testPrimitiveInstanceIntger()
	{
			try
			{
				sendRequest("testPrimitiveInstance","intMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-intMethod");
			}

	}


	public void testPrimitiveInstanceLong()
	{
			try
			{
				sendRequest("testPrimitiveInstance","longMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-longMethod");
			}

	}
	public void testPrimitiveInstanceByte()
	{
			try
			{
				sendRequest("testPrimitiveInstance","byteMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-byteMethod");
			}

	}
	public void testPrimitiveInstanceChar()
	{
			try
			{
				sendRequest("testPrimitiveInstance","charMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-charMethod");
			}

	}
	public void testPrimitiveInstanceString()
	{
			try
			{
				sendRequest("testPrimitiveInstance","stringMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-stringMethod");
			}

	}
	public void testPrimitiveInstanceDouble()
	{
			try
			{
				sendRequest("testPrimitiveInstance","doubleMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-doubleMethod");
			}

	}
	public void testPrimitiveInstanceFloat()
	{
			try
			{
				sendRequest("testPrimitiveInstance","floatMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-floatMethod");
			}

	}
	public void testPrimitiveInstanceBoolean()
	{
			try
			{
				sendRequest("testPrimitiveInstance","booleanMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-booleanMethod");
			}

	}
	public void testPrimitiveInstanceShort()
	{
			try
			{
				sendRequest("testPrimitiveInstance","shortMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveInstance-shortMethod");
			}

	}

///***************************************************************
	///

	///		PRIMITIVE STATIC METHODS
	//
	public void testPrimitiveStaticInteger()
	{
			try
			{
				sendRequest("testPrimitiveStatic","intMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-intMethod");
			}

	}
	public void testPrimitiveStaticLong()
	{
			try
			{
				sendRequest("testPrimitiveStatic","longMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-longMethod");
			}

	}
	public void testPrimitiveStaticByte()
	{
			try
			{
				sendRequest("testPrimitiveStatic","byteMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-byteMethod");
			}

	}
	public void testPrimitiveStaticChar()
	{
			try
			{
				sendRequest("testPrimitiveStatic","charMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-charMethod");
			}

	}
	public void testPrimitiveStaticString()
	{
			try
			{
				sendRequest("testPrimitiveStatic","stringMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-stringMethod");
			}

	}
	public void testPrimitiveStaticDouble()
	{
			try
			{
				sendRequest("testPrimitiveStatic","doubleMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-doubleMethod");
			}

	}
	public void testPrimitiveStaticFloat()
	{
			try
			{
				sendRequest("testPrimitiveStatic","floatMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-floatMethod");
			}

	}
	public void testPrimitiveStaticBoolean()
	{
			try
			{
				sendRequest("testPrimitiveStatic","booleanMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-booleanMethod");
			}

	}
	public void testPrimitiveStaticShort()
	{
			try
			{
				sendRequest("testPrimitiveStatic","shortMethod");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- testPrimitiveStatic-shortMethod");
			}

	}



	///***************************************************************
	//
	//	PRIMTIVE AND OBJECT INSTANCE FIELDS



	public void testSetAndGetPrimitiveFieldBoolean()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","booleanParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-booleanParam");
			}

	}
	public void testSetAndGetPrimitiveFieldByte()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","byteParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-byteParam");
			}

	}
	public void testSetAndGetPrimitiveFieldcharParam()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","charParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-charParam");
			}

	}

	public void testSetAndGetPrimitiveFielddoubleParam()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","doubleParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-doubleParam");
			}

	}
	public void testSetAndGetPrimitiveFieldintParam()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","intParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-intParam");
			}

	}
	public void testSetAndGetPrimitiveFieldfloatParam()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","floatParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-floatParam");
			}

	}
	public void testSetAndGetPrimitiveFieldlongParam()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","longParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-longParam");
			}

	}
	public void testSetAndGetPrimitiveFieldObject()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","objectParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField");
			}

	}
	public void testSetAndGetPrimitiveFieldShort()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","shortParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-shortParam");
			}

	}
	public void testSetAndGetPrimitiveFieldString()
	{
			try
			{
				sendRequest("setAndGetPrimitiveField","stringParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitiveField-stringParam");
			}

	}


	///***************************************************************
	//
	//	PRIMTIVE AND OBJECT STATIC FIELDS



	public void testSetAndGetPrimitveStaticFieldsBoolean()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","booleanParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-booleanParam");
			}

	}


	public void testSetAndGetPrimitveStaticFieldsByte()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","byteParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-byteParam");
			}

	}

	public void testSetAndGetPrimitveStaticFieldsChar()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","charParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-charParam");
			}

	}

	public void testSetAndGetPrimitveStaticFieldsdoubleParam()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","doubleParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-doubleParam");
			}

	}

	public void testSetAndGetPrimitveStaticFieldsFloat()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","floatParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-floatParam");
			}

	}

	public void testSetAndGetPrimitveStaticFieldsInteger()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","intParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-intParam");
			}

	}

	public void testSetAndGetPrimitveStaticFieldsLong()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","longParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-longParam");
			}

	}


	public void testSetAndGetPrimitveStaticFieldsObject()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","objectParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-objectParam");
			}

	}

	public void testSetAndGetPrimitveStaticFieldsShort()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","shortParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-shortParam");
			}

	}
	public void testSetAndGetPrimitveStaticFieldsString()
	{
			try
			{
				sendRequest("setAndGetPrimitveStaticFields","stringParam");
			}
			catch(Exception ex)
			{
				fail("Tiger Runtime failed for the  following method :- setAndGetPrimitveStaticFields-stringParam");
			}

	}




}
